<div class="card">
<div class="card-header">
  <h3 class="card-title">Checks</h3>
  <div class="card-options">
    <span id="notice"><%= notice %></span>
    <%= link_to 'JSON',
      checks_path(format: :json), class: 'btn btn-success btn-sm ml-1'%>
  </div>
</div>
<div class="table-responsive">
<table class="table card-table table-striped table-vcenter">
  <thead>
    <tr>
      <th colspan=2>Active</th>
      <th>Name</th>
      <th>Cron</th>
      <th>Url</th>
      <th>Status</th>
      <th>TLS</th>
      <th></th>
    </tr>
  </thead>

  <tbody>
    <% @checks.each do |check| %>
      <tr>
        <td class="<%= class_for_active(check.active) %>"><i class="fe <%= class_for_active_checkbox(check.active) %>"></i></td>
        <td><%= link_to ('<i class="fe fe-edit"></i>').html_safe, edit_check_path(check) %></td>
        <td>
          <div><strong><%= link_to check.name, check %></strong></div>
          <div class="small text-muted">
            <span class="text-<%= class_for_status(check.status) %>">
              <strong><%= truncate(check.status, :length => 10) %></strong></span>
            <%= time_ago_in_words(check.last_contact_at) + " ago" if check.last_contact_at %>
          </div>
        </td>
        <td class="text-nowrap">
          <div>
            <strong><%= check.cron %></strong>
            <span class="small text-muted float-right"><%= "in " + distance_of_time_in_words(Time.current, check.next_contact_at) if check.next_contact_at %>
            </span>
          </div>
          <div class="small text-muted">
            <%= "Next: " + check.next_contact_at.to_s if check.next_contact_at %>
          </div>
        </td>
        <td>
          <div class="<%= class_for_status(check.status) %>"><%= link_to check.url, check.url %></div>
          <div class="small text-muted"><%= "Last: " + check.last_contact_at.to_s if check.last_contact_at %></div>
        </td>
        <td>
          <% if check.status.to_i.between?(100, 599) %>
            <span class="badge badge-<%= class_for_status(check.status) %>"><%= check.status %></span>
          <% else %>
            <div class="small text-danger">
            <%= truncate(check.status, :length => 37) %>
            </div>
          <% end %>
          <div class="small text-muted"><%= "Changes: " + check.status_changes.count.to_s %></div>
        </td>
        <td>
          <div class="small <%= class_for_tls_expires_in_days(check.tls_expires_in_days) %>">
            <% if !check.active %>
              Check not active
            <% else %>
              <% if URI.parse(check.url).scheme == 'https' %>
                <% if check.tls_expires_at? %>
                  Expires in <%= check.tls_expires_in_days %> days
                <% else %>
                  Waiting for TLS check
                <% end %>
              <% else %>
                No TLS certificate
              <% end %>
            <% end %>
          </div>
        </td>
        <td>
          <%= button_to check, class: "btn btn-outline-danger btn-sm", method: :delete do %>
            <i class="fe fe-trash"></i>
          <% end %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
</div>
</div>
